﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;

namespace ProbeMod.Cards
{
    public sealed class ProbeEnergyRechargeDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();


            config.TargetType = TargetType.Nobody;
            config.Type = CardType.Skill;
            config.Rarity = Rarity.Common;

            config.Colors = new List<ManaColor>() { ManaColor.Blue };
            config.Cost = new ManaGroup() { Blue = 1 };
            config.UpgradedCost = new ManaGroup() {  Any = 1 };

            config.UpgradedKeywords = Keyword.Retain;
            
            config.Value1 = 3;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);

            return config;
        }
    }

    /// <summary>
    /// 快速充能
    /// 
    /// 手牌一张建筑牌+3耐久 抽一张牌
    /// </summary>
    [EntityLogic(typeof(ProbeEnergyRechargeDef))]
    public sealed class ProbeEnergyRecharge : ProbeCard
    {
        public override Interaction Precondition()
        {
            List<Card> list = base.Battle.HandZone.Where((Card hand) => hand != this && hand.CardType == CardType.Friend).ToList();
            return new SelectHandInteraction(1, 1, list);
        }

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            if (precondition != null)
            {
                Card card = ((SelectHandInteraction)precondition).SelectedCards[0];
                if (card != null)
                {
                    card.Loyalty += Value1;
                    yield return new DrawCardAction();
                }
            }
        }
    }
}
